import {
	get,
	post
} from './http.js'
import {
	RequestURL
} from './requestURL.js'
import {
	currentDate,
	futureDate
} from '../timer'

//获取openID
const getOpenID = (jsCode, cinemaCode) => {

	return new Promise((resolve, reject) => {
		get(RequestURL.GET_OPENID, {
			jsCode
		}, cinemaCode).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
export const queryUserInfo = (openId) => {

	return new Promise((resolve, reject) => {
		post(RequestURL.QUERY_USER_INFO, {
			openId
		}).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
export const addUserInfo = (info) => {

	return new Promise((resolve, reject) => {
		post(RequestURL.ADD_USER_INFO, info).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

//获取影院信息
const queryCinema = () => {
	return new Promise((resolve, reject) => {
		get(RequestURL.QUERY_CINEMA).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const getCinemaConfig = () => {
	return new Promise((resolve, reject) => {
		get(RequestURL.GET_CINEMA_CONFIG).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
//获取连锁影院
const getChains = () => {
	return new Promise((resolve, reject) => {
		get(RequestURL.GET_CHAINS).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
//获取最近电影
const queryFilms = (date = {
	StartDate: currentDate(),
	EndDate: futureDate(30)
}) => {

	return new Promise((resolve, reject) => {
		post(RequestURL.QUERY_FILMS, date).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

//获取排期
const querySession = (date = {
	StartDate: currentDate(),
	EndDate: futureDate(30)
}) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.QUERY_SESSION, date).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
const queryNewSession = (date = {
	StartDate: currentDate(),
	EndDate: futureDate(30)
}) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.NEW_QUERY_SESSION, date).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}


//获取排期状态
const querySessionStatus = (date = {
	StartDate: currentDate(),
	EndDate: futureDate(30)
}) => {

	return new Promise((resolve, reject) => {
		post(RequestURL.QUERY_SESSION_STATUS, date).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
//获取当前电影座位状态
const querySessionSeats = (PlanCode) => {
	return new Promise((resolve, reject) => {
		get(RequestURL.QUERY_SESSION_SEATS, {
			PlanCode
		}).then((res) => {
			resolve(res.data.Plans[0].Seats)
		}).catch((err) => {
			reject(err)
		})
	})
}

//获取影厅座位图
const querySeats = (ScreenCode) => {
	return new Promise((resolve, reject) => {
		get(RequestURL.QUERY_SEATS, {
			ScreenCode
		}).then((res) => {
			resolve(res.data.Seats)
		}).catch((err) => {
			reject(err)
		})
	})
}

//锁座
const lockedSeat = (params) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.LOCKED_SEAT, params).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
//解锁座位
const releaseSeat = (params) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.RELEASE_SEATS, params).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
//微信支付
const wxPay = (params, cinemaCode) => {
	return new Promise((resolve, reject) => {
		get(RequestURL.WX_PAY, params, cinemaCode).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
//获取电影票
const quertTicketList = (data) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.QUERY_TICKET_LIST, {
			...data,
			statusList: ["0", "2", "3", "5", "6", '7'],
			orderType: "GP"
		}).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

//微信退票
const wxRefundTicket = (params) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.WX_REFUND_TICKET, params).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
//会员退票
const memberRefundTicket = (params) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.MEMBER_REFUND_TICKET, params).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
//获取优惠券列表
const queryCouponList = (openID) => {
	return new Promise((resolve, reject) => {
		get(RequestURL.QUERY_COUPON_LIST, {
			openId: openID,
		}).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
//获取赠券列表
const queryGiveCouponList = (params) => {
	return new Promise((resolve, reject) => {
		get(RequestURL.QUERY_GIVE_COUPON_LIST, params).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
//绑卡
const UserBindCard = (params) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.BIND_CARD, params).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

//获取会员卡列表
const getCardList = (openId) => {
	return new Promise((resolve, reject) => {
		get(RequestURL.QUERY_CARD_LIST, {
			openId
		}).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

//获取会员卡政策
const getMemberCard = () => {
	return new Promise((resolve, reject) => {
		get(RequestURL.GET_MEMBER_CARD).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
//获取会员价
const getMemberPrice = (params) => {
	return new Promise((resolve, reject) => {
		get(RequestURL.GET_MEMBER_PRICE, params).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const payByMemberCard = (params) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.PAY_BY_CARD, params).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const payByCoupons = (params) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.PAY_BY_COUPONS, params).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const payByGiveCoupons = (params) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.PAY_BY_GIVE_COUPONS, params).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
//查询订单信息 
const queryOrderInfo = (orderCode) => {
	return new Promise((resolve, reject) => {
		get(RequestURL.QUERY_ORDER_INFO, {
			orderCode
		}).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const getCardInfo = (cardInfo) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.GET_CARD_INFO, cardInfo).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const getCardPolicy = () => {
	return new Promise((resolve, reject) => {
		get(RequestURL.QUERY_CARD_POLICY).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

//获取充值金额
const getRechargeAmount = (rechareParams) => {
	return new Promise((resolve, reject) => {
		get(RequestURL.GET_RECHARGE_AMOUNT).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}


const creatRechargeOrder = (rechareParams) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.CREATE_RECHARGE_ORDER, rechareParams).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const rechargePay = (payParams) => {
	return new Promise((resolve, reject) => {
		get(RequestURL.RECHARGE_PAY, payParams).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const getCostList = (payParams) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.GET_COST_LIST, payParams).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const getRechargeList = (payParams) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.GET_RECHARGE_LIST, payParams).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const createCouponOrder = (payParams, cinemaCode) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.CREATE_COUPON_ORDER, payParams, cinemaCode).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const openCard = (params) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.OPEN_CARD, params).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const bindMemberCard = (params) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.BIND_MEMBER_CARD, params).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const getCouponInfo = (policyId, cinemaCode) => {
	return new Promise((resolve, reject) => {
		get(RequestURL.GET_COUPON_INFO, {
			policyId
		}, cinemaCode).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}


const getCouponOrderInfo = (couponOrderCode, cinemaCode) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.GET_COUPON_ORDER_INFO, {
			couponOrderCode
		}, cinemaCode).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const loginUser = (params) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.LOGIN_USER, params).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
const modifyAccount = (params) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.MODIFY_USER, params).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const getSaleOrders = (phone) => {
	return new Promise((resolve, reject) => {
		get(RequestURL.GET_SALE_ORDERS, {
			phone
		}).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const withdrawCash = (params) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.WITHDRAW_CASH, params).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const getWithdrawRecord = (phone) => {
	return new Promise((resolve, reject) => {
		get(RequestURL.WITHDRAW_CASH_RECORD, {
			phone
		}).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const getCinemaInfo = () => {
	return new Promise((resolve, reject) => {
		get(RequestURL.GET_CINEMA_INFO).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const getUserPhone = (data) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.GET_USER_PHONE, data).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const sendCode = (data) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.GET_VERITY_CODE, data).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const checkCode = (data) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.CHECK_VERITY_CODE, data).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

const getGiveMoney = (data) => {
	return new Promise((resolve, reject) => {
		post(RequestURL.GET_GIVE_MONEY, data).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
export function getGiveCoupon(data) {
	return new Promise((resolve, reject) => {
		post(RequestURL.GET_GIVE_COUPON, data).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

//商城接口
export function goodsList() {
	return new Promise((resolve, reject) => {
		post(RequestURL.QUERY_GOODS_LIST).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

//会员商品
export function memberGoodsList() {
	return new Promise((resolve, reject) => {
		post(RequestURL.QUERY_MEMBER_GOODS_LIST).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

export function goodsOrder(data) {
	return new Promise((resolve, reject) => {
		post(RequestURL.CREATE_GOODS_ORDER, data).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

export function goodsOrderList(data) {
	return new Promise((resolve, reject) => {
		post(RequestURL.QUERY_GOODS_ORDER_LIST, data).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

export function goodsOrderStatus(data) {
	return new Promise((resolve, reject) => {
		post(RequestURL.QUERY_GOODS_ORDER, data).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}


export function goodsOrderPrient(data) {
	return new Promise((resolve, reject) => {
		post(RequestURL.QUERY_GOODS_ORDER_PRIENT, data).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

export function goodsMeberPay(data) {
	return new Promise((resolve, reject) => {
		post(RequestURL.GOODS_MEMBER_PAY, data).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

export function douyinPayApi(data) {
	return new Promise((resolve, reject) => {
		post(RequestURL.DOUYIN_COUPON_PAY, data).then((res) => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

export {
	queryCinema,
	getCinemaConfig,
	getChains,
	queryFilms,
	querySession,
	queryNewSession,
	querySessionStatus,
	getOpenID,
	querySeats,
	querySessionSeats,
	lockedSeat,
	wxPay,
	quertTicketList,
	queryCouponList,
	queryGiveCouponList,
	UserBindCard,
	getCardList,
	getMemberPrice,
	payByMemberCard,
	queryOrderInfo,
	releaseSeat,
	wxRefundTicket,
	memberRefundTicket,
	getCardInfo,
	getMemberCard,
	getCardPolicy,
	creatRechargeOrder,
	rechargePay,
	getRechargeList,
	getCostList,
	openCard,
	bindMemberCard,
	getCouponInfo,
	createCouponOrder,
	loginUser,
	modifyAccount,
	withdrawCash,
	getSaleOrders,
	getWithdrawRecord,
	payByCoupons,
	payByGiveCoupons,
	getCinemaInfo,
	getUserPhone,
	sendCode,
	checkCode,
	getGiveMoney,
	getRechargeAmount,
	getCouponOrderInfo
}